package google.util;

import db.dao.BaseDao;
import domain.company.Company6;
import domain.task.Task6;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhongwei on 616/1/1.
 */
public class Gen {
    static BaseDao baseDao = new BaseDao();
    private File file;

    public static void main(String[] args) throws IOException, URISyntaxException {
        List<String> weeks = FileUtils.readLines(new File(ClassLoader.getSystemResource("weeks_all.txt").toURI()));
        File file = new File("company" + File.separator + "company_list_6");
        List<String> list = FileUtils.readLines(file);
        // [COMPANY]&safe=strict&tbs=cdr:1,cd_min:[START],cd_max:[END]&tbm=nws
        String template = "&safe=strict&tbs=cdr:1,cd_min:[START],cd_max:[END]&tbm=nws";
        for (String str : list) {
            Company6 company6 = new Company6();
            company6.setCompanyName(str);
            baseDao.create(company6);
            List<Task6> list1 = new ArrayList<>();
            for (String week : weeks) {
                Task6 task6 = new Task6();
                String[] arr1 = week.split("/");
                String start = arr1[0].replace("-", "/");
                String end = arr1[1].replaceAll("-", "/");
                task6.setUrl("[HOST]" + str + template.replace("[START]", start).replace("[END]", end));
                task6.setDone(0);
                list1.add(task6);
            }
            baseDao.create(list1, list1.size());
        }
    }
}
